<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>次品退货列表</title>

<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script> 
<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>

<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		商品管理 &gt; 次品退货管理
</div>
<br />
<form action="#" name="queryForm" id="queryForm" method="POST" >
<div id="searchbar"><br>
退货编号：<input type="text" id="defectReplceId" name="defectReplceId" value="${defectReplceVo.defectReplceId}" />&nbsp;&nbsp;
<br/>
<br/>
处理状态： <select id="processState" name="processState">
         		<option value="0" ${defectReplceVo.processState == 0 ? "selected='selected'" : ""}>请选择</option>
         		<option value="1" ${defectReplceVo.processState == 1 ? "selected='selected'" : ""}>待退货出库</option>
         		<option value="2" ${defectReplceVo.processState == 2 ? "selected='selected'" : ""}>已生成出库单</option>
         		<option value="3" ${defectReplceVo.processState == 3 ? "selected='selected'" : ""}>退货处理完成</option>
<%--          		<option value="4" ${defectReplceVo.processState == 4 ? "selected='selected'" : ""}>待换货入库</option>
         		<option value="5" ${defectReplceVo.processState == 5 ? "selected='selected'" : ""}>已生成入库单</option>
         		<option value="6" ${defectReplceVo.processState == 6 ? "selected='selected'" : ""}>换货处理完成</option> --%>
         	</select> &nbsp;&nbsp;&nbsp;&nbsp;
         	<div  style="display: none;">
      业务类型： <select id="replceType" name="replceType">
            <option value="0">请输入</option>
      		<option value="1" ${defectReplceVo.replceType == 1 ? "selected='selected'" : ""}>退货</option>
      		<option value="2" ${defectReplceVo.replceType == 2 ? "selected='selected'" : ""}>换货</option>
      	</select> &nbsp;&nbsp; 
      	</div>
      <input type="submit" id="btnSearch" value="查询" class="l-button-search" />
      <input type="button" id="btnReset" value="重置" class="l-button-search" />
</div>
</form>
<br />
<div id="maingrid" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- 展示列表数据  -->
</div>
	<script>
    var basePath='${BasePath}';
    var grid = null;
	
    $(function () {
    	 // 重置
        $("#btnReset").click(function(){
    		$('#searchbar :input').not(':submit, :button, :reset').val('').removeAttr('checked').removeAttr('selected');
    	});
        grid = $("#maingrid").ligerGrid({
            columns: [
            { display: '退货编号', name: 'defectReplceId'},
            { display: '退货名称', name: 'defectReplceName'},
           /*  { display: '退换货类型', name: 'replceType', width: '7%', render: function (rowdata, rowindex, value) {
            	if (value == 1) {
            		return '退货';
            	} else if (value == 2) {
            		return '换货';
            	}  else {
            		return '';
            	}
            } }, */
            /* { display: '处理状态', name: 'processState', width: '7%', render: function (rowdata, rowindex, value) {
            	if (value == 1) {
            		return '待退货出库';
            	} else if (value == 2) {
            		return '待换货入库';
            	}  else if (value == 3) {
            		return '退出库完成';
            	}  else if (value == 4) {
            		return '换货入库完成';
            	}   else {
            		return '';
            	}
            } }, */
            { display: '数量', name: 'defectiveNumber'},
            { display: '规格', name: 'specName'},
            { display: '供应商名称', name: 'supName'},
            { display: '仓库名称', name: 'whName'},
           /*  { display: '审核人', name: 'auditor'}, */
            { display: '创建时间 ', name: 'createTime'},
             { display: '发起人', name: 'initiater'}, 
             /*  { display: '发起时间', name: 'initiateTime'},*/
            /* { display: '商品描述', name: 'proDesc'}, */
             { display: '处理状态', name: 'processState', render: function (rowdata, rowindex, value){
            	 if(value == 1){
            		return '待生成出库单'
            	}else if(value == 2){
            		return '已生成出库单';
            	}else if(value == 3){
            		return '退货处理完成'
            	}else if(value == 4){
            		return '待换货入库'
            	}else if(value == 5){
            		return '已生成入库单'
            	}else if(value == 6){
            		return '换货处理完成'
            	}else {
            		return ''
            	}
             }},
            {display: '操作',width:'15%', isSort: false, render: function (rowdata, rowindex, value){
	             	var h = "";
	             	if(rowdata.processState== 1){
	             	 	h += "<a href='javascript:showPoDetail(\"" + rowdata.defectReplceId + "\")'>详情</a>&nbsp;";
	             	 	h += "<a href='javascript:deleteDefective(" + rowindex + ")'>作废</a> ";
	             	 	var text = null;
	             	 	if (rowdata.replceType == 1){
	             	 		text = "退货出库";
	             	 	}else{
	             	 		text = "换货出库";
	             	 	}
	             	 	h += "<a href='javascript:Storage(\"" + rowdata.defectReplceId + "\")'>"+text+"</a>";
	             	}else if(rowdata.processState == 4 && rowdata.replceType == 2){
	             		h += "<a href='javascript:showPoDetail(\"" + rowdata.defectReplceId + "\")'>详情</a>&nbsp;";
	             		h += "<a href='javascript:stockIn(\"" + rowdata.defectReplceId + "\")'>换货入库</a> ";
	             		
	             	}else{
	             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.defectReplceId + "\")'>详情</a>&nbsp;";
	             	}
	                return h;
            	}
            }
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
					{name: "defectReplceId", value:$("#defectReplceId").val()},
					{name: "replceType", value:$("#replceType").val()},
					{name: "processState", value:$("#processState").val()},
                    ],
			url: basePath+'/product/defectiveReplacement/list_replacement.do',
			toolbar: toolbar
        });
    });
    var toolbar = '';
    toolbar = {
    	items: [
    			{ text: "创建次品退货", click: addDefective, icon: "add" }
        		]
       		 };
    
    /**
     * 新增次品退货信息
     */
    function addDefective(){
    		var url=basePath+'/product/defectiveReplacement/to_add_defectReplce.do';
        	url+="?pTabid="+WIN_TAB.getSelectedTabItemID();
        	window.parent.f_addTab('新增次品退货','新增次品退货',url);
    }
     
    /**
     * 修改次品信息
     */
    function updateDefective(rowindex){
    	 var productId=grid.getData()[rowindex].productId;
    	 
          var url=basePath+'/product/defectivemgt/to_update_defective.do?productId='+productId;
          url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
    	  window.parent.f_addTab('修改次品信息','修改次品信息',url);
    }
    
    /**
     * 次品退货详情
     * @param poNo
     */
    function showPoDetail(defectReplceId) {
    	window.parent.f_addTab("次品退货详情", "次品退货详情", basePath+'/product/defectiveReplacement/showPoDetail.do?DefectReplceId=' + defectReplceId);
    }
    
    /**
     * 次品退换货出库
     * @param puNo
     */
    function Storage(defectReplceId) {
     	var tabId = window.top.tab.getSelectedTabItemID();
  	    var url = basePath+'/product/defectiveReplacement/AddStockOutForPurchase.do?defectReplceId=' + defectReplceId+'&tabId='+tabId;
    	window.parent.f_addTab("次品退货出库", "次品退货出库", url);
    }
    
    
    /**
     * 次品退换货入库
     * @param puNo
     */
    function stockIn(defectReplceId) {
     	var tabId = window.top.tab.getSelectedTabItemID();
  	    var url = basePath+'/stockmanage/StockController/toDefectReplceStockIn.do?defectReplceId=' + defectReplceId+'&tabId='+tabId;
    	window.parent.f_addTab("次品退货入库", "次品退货入库", url);
    }
    
    
    /**
     * 删除次品信息
     */
    function deleteDefective(rowindex) {
    	var id=grid.getData()[rowindex].defectReplceId;
    	$.ligerDialog.confirm('确定删除',
    		function(yes) {if (yes) {
    			$.post(
    					basePath+ '/product/defectiveReplacement/deleteDefective.do',
    					{defectiveReplceNo : id},
    					function(data) {
    						if (data == 'success') {
    							window.parent.f_tip('删除成功');
    							window.location.reload();
    						} else if (data == 'fail') {
    							window.parent.f_tip('删除失败');
    						}else{
    							window.parent.f_tip(data);
    						};
    					}
    			);
    		};
    	});
    }
    
    
    var toolbar;
    var roles = new Array();
    '<c:forEach items="${roleVos}" var="item">';
    roles.push('${item.roleCode}');
    '</c:forEach>';
    
    var rpm = 0;
	if (roles.length > 0) {
		var ex = [];
		var add = [];
		var items = [];
		for(var i=0; i<roles.length; i++) {
			//商品主管,管理员
       		if(roles[i] == 'GOOD_PERSON' || roles[i] == 'SYSTEM_ADMIN'){
    			add = [{ text: "新增次品",id:"add", click: addCommodity, icon: "add"},{ line: true }];
    		}
    		if (roles[i] == 'GOODS_SUPERVISOR' || roles[i] == 'FINANCIAL_PRINCIPAL'  || roles[i] == 'SYSTEM_ADMIN') {
    			ex = [{text: '导出EXCEL', click: doExportExcel, icon: "print"},{ line: true }];
    		}
    	}
		items = items.concat(ex);
		items = items.concat(add);
		toolbar = {items : items};
	}
    
   
    </script>
	
</body>
</html>